<template>
	<view class="order">
		<van-tabs v-model:active="active">
			<van-tab title="待付款">
				<van-card v-for="(cg,cg_idx) in cartGoods" :num="cg.num" :price="cg.price" :origin-price="cg.pre_price"
					:desc="cg.desc" :title="cg.name" :thumb="cg.src">
					<template #tags>
						<van-tag plain type="danger">优惠￥{{cg.discount}}元</van-tag>
					</template>
				</van-card>
			</van-tab>
			<van-tab title="待发货">内容 2</van-tab>
			<van-tab title="待收货">
				<view class="order" v-for="g3 in goods3">
					<van-cell :value="'订单号：'+g3._id"></van-cell>
					<van-card v-for="(cg,cg_idx) in g3.goods_list" :num="cg.num" :price="cg.price" :desc="cg.desc"
						:title="cg.name" :thumb="cg.goods_thumb">
					</van-card>
					<view class="">
						<van-button type="warning" size="small" @click="sureGetGoods(g3._id)">确认收货</van-button>
					</view>
				</view>

			</van-tab>
			<van-tab title="待评论">
				<view class="order" v-for="g4 in goods4">
					<van-cell :value="'订单号：'+g4._id"></van-cell>
					<van-card v-for="(cg,cg_idx) in g4.goods_list" :num="cg.num" :price="cg.price" :desc="cg.desc"
						:title="cg.name" :thumb="cg.goods_thumb">
						<template #footer>
							<view v-if="!cg.is_comment">
								<van-button @click="commentGoods(cg.goods_id,cg_idx,g4._id)"  type="default" size="small">评价</van-button>
							</view>
						</template>
					</van-card>
				</view>
			</van-tab>
			<van-tab title="全部订单">
				<van-card v-for="(cg,cg_idx) in cartGoods" :num="cg.num" :price="cg.price" :origin-price="cg.pre_price"
					:desc="cg.desc" :title="cg.name" :thumb="cg.src">
					<template #tags>
						<van-tag plain type="danger">优惠￥{{cg.discount}}元</van-tag>
					</template>
				</van-card>
			</van-tab>
		</van-tabs>

	</view>
</template>

<script>
	import {
		ref
	} from 'vue';
	import cartGoodsData from '@/json/cart.json'
	const Order = uniCloud.importObject('order')
	export default {
		setup(opt) {
			const active = ref(opt.index - 0);
			return {
				active
			};
		},
		data() {
			return {
				cartGoods: [],
				goods3: []
			}
		},
		onLoad() {
			this.getOrder()
		},
		methods: {
			getOrder() {
				Order.getOrderGoods().then(res => {
					this.goods2 = res.goods2
					this.goods3 = res.goods3
					this.goods4 = res.goods4
				})
			},
			sureGetGoods(id) {
				let that = this;
				uni.showModal({
					title:"确认收货",
					content:"确定收到货物了吗？一但确定不能修改！",
					success(s) {
						if(s.confirm){
							Order.sure(id).then(res=>{
								console.log(res);
								that.getOrder()
							})
						}
					}
				})
			},
			commentGoods(id,index,order_id){
				uni.navigateTo({
					url:`/pages/goods/comment?order_id=${order_id}&id=${id}&index=${index}`
				})
			}
		}
	};
</script>

<style>
</style>
